Jump to content

Module:Ofs-decl-noun

Frae Wikipedia, the free beuk o knawledge
local export = {}

local m_links = require("Module:links")
local m_utils = require("Module:utilities")

local lang = require("Module:languages").getByCode("ofs")

local decl_data = {}

decl_data["a-m"] = {
	params = {
		[1] = {},
		[2] = {},
		["pal"] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["a-m"], {__call = function(self, args, data)
	data.decl_type = "masculine a-stem"
	
	local a2 = args[2] or args[1]
	
	data.forms["nom_sg"] = {args.pal or args[1]}
	data.forms["acc_sg"] = {args.pal or args[1]}
	data.forms["gen_sg"] = {(args.pal or (args[2] or (args[1] .. "e"))) .. "s"}
	data.forms["dat_sg"] = {args.pal or (args[2] or (args[1] .. "e"))}

	if not args.nopl then
		data.forms["nom_pl"] = {a2 .. "ar", a2 .. "a"}
		data.forms["acc_pl"] = {a2 .. "ar", a2 .. "a"}
		data.forms["gen_pl"] = {a2 .. "a"}
		data.forms["dat_pl"] = {a2 .. "um", a2 .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian a-stem nouns")
end
})

decl_data["a-n"] = {
	params = {
		[1] = {},
		[2] = {},
		["nopl"] = {},
		["short"] = {},
	},
}
setmetatable(decl_data["a-n"], {__call = function(self, args, data)
	data.decl_type = "neuter a-stem"

	local a2 = args[2] or args[1]
	
	data.forms["nom_sg"] = {args[1]}
	data.forms["acc_sg"] = {args[1]}
	data.forms["gen_sg"] = {(args[2] or (args[1] .. "e")) .. "s"}
	data.forms["dat_sg"] = {args[2] or (args[1] .. "e")}

	if not args.nopl then
		data.forms["nom_pl"] = {args.short and (a2 .. "e") or args[1], args.short and (a2 .. "u")}
		data.forms["acc_pl"] = {args.short and (a2 .. "e") or args[1], args.short and (a2 .. "u")}
		data.forms["gen_pl"] = {a2 .. "a"}
		data.forms["dat_pl"] = {a2 .. "um", a2 .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian a-stem nouns")
end
})

decl_data["cons-m"] = {
	params = {
		[1] = {},
		[2] = {},
		[3] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["cons-m"], {__call = function(self, args, data)
	data.decl_type = "masculine consonant stem"
	
	local a3 = args[3] or args[1]
	
	data.forms["nom_sg"] = {args[1]}
	data.forms["acc_sg"] = {args[1]}
	data.forms["gen_sg"] = {a3 .. "es"}
	data.forms["dat_sg"] = {a3 .. "e"}

	if not args.nopl then
		data.forms["nom_pl"] = {args[2] or args[1]}
		data.forms["acc_pl"] = {args[2] or args[1]}
		data.forms["gen_pl"] = {a3 .. "a"}
		data.forms["dat_pl"] = {a3 .. "um", a3 .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian consonant stem nouns")
end
})

decl_data["cons-f"] = {
	params = {
		[1] = {},
		[2] = {},
		[3] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["cons-f"], {__call = function(self, args, data)
	decl_data["cons-m"](args, data)
	
	data.decl_type = "feminine consonant stem"

	data.forms["gen_sg"][2] = (args[3] or args[1]) .. "e"
end
})

decl_data["i-f"] = {
	params = {
		[1] = {},
		["short"] = {},
		["nopl"] = {},
		},
}
setmetatable(decl_data["i-f"], {__call = function(self, args, data)
	data.decl_type = "feminine i-stem"

	data.forms["nom_sg"] = {args[1] .. (args.short and "e" or "")}
	data.forms["acc_sg"] = {args[1] .. (args.short and "e" or "")}
	data.forms["gen_sg"] = {args[1] .. "e"}
	data.forms["dat_sg"] = {args[1] .. "e"}

	if not args.nopl then
		data.forms["nom_pl"] = {args[1] .. "a"}
		data.forms["acc_pl"] = {args[1] .. "a"}
		data.forms["gen_pl"] = {args[1] .. "a", args[1] .. "ena"}
		data.forms["dat_pl"] = {args[1] .. "um", args[1] .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian i-stem nouns")
end
})

decl_data["ja-m"] = {
	params = {
		[1] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["ja-m"], {__call = function(self, args, data)
	data.decl_type = "masculine ja-stem"

	data.forms["nom_sg"] = {args[1] .. "e"}
	data.forms["acc_sg"] = {args[1] .. "e"}
	data.forms["gen_sg"] = {args[1] .. "es"}
	data.forms["dat_sg"] = {args[1] .. "e"}

	if not args.nopl then
		data.forms["nom_pl"] = {args[1] .. "ar", args[1] .. "a"}
		data.forms["acc_pl"] = {args[1] .. "ar", args[1] .. "a"}
		data.forms["gen_pl"] = {args[1] .. "a"}
		data.forms["dat_pl"] = {args[1] .. "um", args[1] .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian ja-stem nouns")
end
})

decl_data["ja-n"] = {
	params = {
		[1] = {},
		[2] = {},
		["nopl"] = {},
		["short"] = {},
	},
}
setmetatable(decl_data["ja-n"], {__call = function(self, args, data)
	data.decl_type = "neuter ja-stem"

	local a2 = args[2] or args[1]
	
	data.forms["nom_sg"] = {args[1] .. (args.short and "e" or "")}
	data.forms["acc_sg"] = {args[1] .. (args.short and "e" or "")}
	data.forms["gen_sg"] = {a2 .. "es"}
	data.forms["dat_sg"] = {a2 .. "e"}

	if not args.nopl then
		data.forms["nom_pl"] = {args.short and (args[1] .. "e") or (a2 .. "e"), args.short and (a2 .. "u")}
		data.forms["acc_pl"] = {args.short and (args[1] .. "e") or (a2 .. "e"), args.short and (a2 .. "u")}
		data.forms["gen_pl"] = {a2 .. "a"}
		data.forms["dat_pl"] = {a2 .. "um", a2 .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian ja-stem nouns")
end
})

decl_data["n-m"] = {
	params = {
		[1] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["n-m"], {__call = function(self, args, data)
	data.decl_type = "masculine n-stem"

	data.forms["nom_sg"] = {args[1] .. "a"}
	data.forms["acc_sg"] = {args[1] .. "a"}
	data.forms["gen_sg"] = {args[1] .. "a"}
	data.forms["dat_sg"] = {args[1] .. "a"}

	if not args.nopl then
		data.forms["nom_pl"] = {args[1] .. "a"}
		data.forms["acc_pl"] = {args[1] .. "a"}
		data.forms["gen_pl"] = {args[1] .. "ena"}
		data.forms["dat_pl"] = {args[1] .. "um", args[1] .. "em"}
	end
	
	table.insert(data.categories, "Old Frisian n-stem nouns")
end
})

decl_data["n-f"] = {
	params = {
		[1] = {},
		["nopl"] = {},
		},
}
setmetatable(decl_data["n-f"], {__call = function(self, args, data)
	decl_data["n-m"](args, data)
	
	data.decl_type = "feminine n-stem"
	
	data.forms["nom_sg"] = {args[1] .. "e"}
end
})

decl_data["n-n"] = {
	params = {
		[1] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["n-n"], {__call = function(self, args, data)
	decl_data["n-m"](args, data)
	
	data.decl_type = "neuter n-stem"
	
	data.forms["nom_sg"] = {args[1] .. "e"}
	data.forms["acc_sg"] = {args[1] .. "e"}
	
	if not args.nopl then
		data.forms["nom_pl"][2] = args[1] .. "ene"
		data.forms["nom_pl"][3] = args[1] .. "ne"
		data.forms["acc_pl"][2] = args[1] .. "ene"
		data.forms["acc_pl"][3] = args[1] .. "ne"
		data.forms["dat_pl"][3] = args[1] .. "num"
		data.forms["dat_pl"][4] = args[1] .. "nem"
	end
end
})

decl_data["o-f"] = {
	params = {
		[1] = {},
		["nopl"] = {},
		},
}
setmetatable(decl_data["o-f"], {__call = function(self, args, data)
	data.decl_type = "ō-stem"
	
	data.forms["nom_sg"] = {args[1] .. "e"}
	data.forms["acc_sg"] = {args[1] .. "e"}
	data.forms["gen_sg"] = {args[1] .. "e"}
	data.forms["dat_sg"] = {args[1] .. "e"}

	if not args.nopl then
		data.forms["nom_pl"] = {args[1] .. "a"}
		data.forms["acc_pl"] = {args[1] .. "a"}
		data.forms["gen_pl"] = {args[1] .. "a", args[1] .. "ena"}
		data.forms["dat_pl"] = {args[1] .. "um", args[1] .. "em"}
	end

	table.insert(data.categories, "Old Frisian ō-stem nouns")
end
})

decl_data["r-f"] = {
	params = {
		[1] = {},
		["nopl"] = {},
		},
}
setmetatable(decl_data["r-f"], {__call = function(self, args, data)
	data.decl_type = "feminine r-stem"
	
	data.forms["nom_sg"] = {args[1] .. "er"}
	data.forms["acc_sg"] = {args[1] .. "er"}
	data.forms["gen_sg"] = {args[1] .. "er", args[1] .. "ere"}
	data.forms["dat_sg"] = {args[1] .. "er", args[1] .. "ere"}

	if not args.nopl then
		data.forms["nom_pl"] = {args[1] .. "er", args[1] .. "era"}
		data.forms["acc_pl"] = {args[1] .. "er", args[1] .. "era"}
		data.forms["gen_pl"] = {args[1] .. "era"}
		data.forms["dat_pl"] = {args[1] .. "rum", args[1] .. "rem", args[1] .. "erum", args[1] .. "erem"}
	end

	table.insert(data.categories, "Old Frisian r-stem nouns")
end
})

decl_data["r-m"] = {
	params = {
		[1] = {},
		["nopl"] = {},
	},
}
setmetatable(decl_data["r-m"], {__call = function(self, args, data)
	decl_data["r-f"](args, data)
	
	data.decl_type = "masculine r-stem"
	
	data.forms["gen_sg"][2] = args[1] .. "eres"
end
})

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)

	local parent_args = frame:getParent().args
	local decl_type = (frame.args["decl"] or parent_args["decl"]) or "a-m"

	if not decl_data[decl_type] then
		error("Unknown declension '" .. decl_type .. "'")
	end
	
	local data = {forms = {}, categories = {}}
	
	data.head = parent_args["head"] or nil

	local args = require("Module:parameters").process(parent_args, decl_data[decl_type].params, true)
	
	-- Override for templates
	if not args[1] then
		setmetatable(args, {__index = function(self, key)
			return "{{{" .. key .. "}}}"
		end
		})
	end
	
	-- Generate the forms
	if parent_args.irr then
		table.insert(data.categories, "Old Frisian irregular nouns")
		if decl_data.irregular[parent_args.irr] then
			decl_data.irregular[parent_args.irr](data)
		else
			decl_data[decl_type](args, data)
		end
	else
		decl_data[decl_type](args, data)
	end

	-- Make the table
	return make_table(data)
end

function make_table(data)
	local function show_form(form)
		if not form then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
				subform = "*" .. subform
			end
			table.insert(ret, m_links.full_link({lang = lang, term = subform}))
		end
			
		return table.concat(ret, ", ")
	end
	
	local function repl(param)
		if param == "decl_type" then
			return data.decl_type
		else
			return show_form(data.forms[param])
		end
	end

	local wikicode = [=[<div class="NavFrame" style="width:30em">
<div class="NavHead" style="">Declension of {{{nom_sg}}} ({{{decl_type}}})</div>
<div class="NavContent">

{| style="background:#F5FFFA;text-align:center;width:30em" class="inflection-table"
|-
! style="background:#F5FFFA" | case
! style="background:#93C572; width: 37.5%" | singular
! style="background:#93C572; width: 37.5%" | plural
|-
! style="background:#90EE90" | [[Appendix:Glossary#nominative case|nominative]]
| {{{nom_sg}}}
| {{{nom_pl}}}
|-
! style="background:#90EE90" | [[Appendix:Glossary#accusative case|accusative]]
| {{{acc_sg}}}
| {{{acc_pl}}}
|-
! style="background:#90EE90" | [[Appendix:Glossary#genitive case|genitive]]
| {{{gen_sg}}}
| {{{gen_pl}}}
|-
! style="background:#90EE90" | [[Appendix:Glossary#dative case|dative]]
| {{{dat_sg}}}
| {{{dat_pl}}}
|}</div></div>]=]

	return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end

return export